package mytools;

import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.sxpjyy.monkey.mobilenurse.R;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.scalars.ScalarsConverterFactory;
import service.MNService;

/**
 * Created by Monkey on 2017/11/1.
 * Service工具类
 */
public class MyServiceUtil {

    private static SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(ApplicationUtil.applicationContext);
    private static String serverAdd = sharedPreferences.getString("server_address", ApplicationUtil.applicationContext.getString(R.string.default_server));
    private static String baseUrl1 = "http://" + serverAdd;

    private static OkHttpClient client = new OkHttpClient.Builder()
            .connectTimeout(20, TimeUnit.SECONDS)
            .readTimeout(20, TimeUnit.SECONDS)
            .writeTimeout(20, TimeUnit.SECONDS)
            .build();
    private static Retrofit retrofit1 = new Retrofit.Builder()
            .baseUrl(baseUrl1)
            .client(client)
            .addConverterFactory(ScalarsConverterFactory.create())
            .build();

    private static MNService mnService = retrofit1.create(MNService.class);

    public static Call<String> getSystemTimeCall() { //获取系统时间
        return mnService.getSystemTime();
    }

    public static Call<String> getSBXHCall(String serial, String mac) {
        return mnService.getSBXH(serial, mac);
    }

    public static Call<String> loginQuery(String jsonString) {
        return mnService.loginQuery(jsonString);
    }

}

